package org.example.leetCode;

/**
 * @author Administrator
 */
public class RemoveElement {
    public int removeElement(int[] nums, int val) {
        if (nums.length == 1 && nums[0] == val) {
            return 0;
        }
        int end = nums.length - 1;
        for (int i = 0; i <= end; i++) {
            while (nums[i] == val) {
                int temp = nums[i];
                nums[i] = nums[end];
                nums[end] = temp;
                end--;
            }
        }
        return ++end;
    }
}
